package org.example.ag_notes.config;

import io.jsonwebtoken.SignatureAlgorithm;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "app.jwt")
public class JwtProperties {
    private String secret; // Base64编码的密钥
    private SignatureAlgorithm algorithm = SignatureAlgorithm.HS256; // 默认使用HS256
    private long accessTokenExpirationMs = 3600000; // 1小时
    private long refreshTokenExpirationMs = 2592000000L; // 30天

    // 自动根据算法确定最小密钥长度
    public int getRequiredKeyLength() {
        return switch (algorithm) {
            case HS256 -> 32; // 256位
            case HS384 -> 48; // 384位
            case HS512 -> 64; // 512位
            default -> throw new IllegalArgumentException("不支持的算法: " + algorithm);
        };
    }
}